package st.lib.base.delegate.mvp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import st.lib.base.delegate.BaseDelegate;

/**
 * @author zhangyu
 * @date 2018/10/15
 */

public abstract class MvpDelegate<T extends BasePresenter> extends BaseDelegate {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mPresenter = getPresenter();
        if (mPresenter != null) {
            mPresenter.subscribe();
        }
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        if (mPresenter != null) {
            mPresenter.unSubscribe();
        }
        super.onDestroyView();
    }

    protected T mPresenter;

    abstract public T getPresenter();
}
